<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" label-position="right" label-width="80px">
        <el-form-item label="用户名字:">
          <el-input v-model="formData.userName" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="用户openID:">
          <el-input v-model="formData.openId" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="创建时间:">
          <el-date-picker v-model="formData.createTime" type="date" placeholder="选择日期" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="用户头像:">
          <el-input v-model="formData.header" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="当日滑雪完成状态（0-未完成；1-已完成）:">
          <el-select v-model="formData.skyStatus" placeholder="请选择" clearable>
            <el-option v-for="(item,key) in 状态Options" :key="key" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="当日邀请用户数（用于校验邀请人数量状态）3表示已完成:">
          <el-input v-model.number="formData.invetNum" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="分享朋友圈状态（0-未分享；1-分享成功）:">
          <el-select v-model="formData.shareStatus" placeholder="请选择" clearable>
            <el-option v-for="(item,key) in 状态Options" :key="key" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="问答完成状态（0-未完成；1-已完成）:">
          <el-select v-model="formData.askStatus" placeholder="请选择" clearable>
            <el-option v-for="(item,key) in 状态Options" :key="key" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="挤牛奶活动完成状态（0-已完成；1未完成）:">
          <el-select v-model="formData.milkStatus" placeholder="请选择" clearable>
            <el-option v-for="(item,key) in 状态Options" :key="key" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="点击进入小程序完成数（进入一个不同的小程序+1）6表示完成活动:">
          <el-input v-model.number="formData.programNum" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="用户拥有的奶滴数量:">
          <el-input v-model.number="formData.milkDripsNum" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="有效状态（0-有效；1-无效）:">
          <el-input v-model.number="formData.isDelete" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="活动当前有效时间。校验活动是否为今日活动数据:">
          <el-date-picker v-model="formData.updateTime" type="date" placeholder="选择日期" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="当日签到状态:">
          <el-select v-model="formData.signStatus" placeholder="请选择" clearable>
            <el-option v-for="(item,key) in 状态Options" :key="key" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="签到次数:">
          <el-input v-model.number="formData.signNum" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="版本好:">
          <el-input v-model.number="formData.version" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="save">保存</el-button>
          <el-button size="mini" type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  createUserInfo,
  updateUserInfo,
  findUserInfo
} from '@/api/userInfo' //  此处请自行替换地址
import infoList from '@/mixins/infoList'
export default {
  name: 'UserInfo',
  mixins: [infoList],
  data() {
    return {
      type: '',
      状态Options: [],
      formData: {
        userName: '',
        openId: '',
        createTime: new Date(),
        header: '',
        skyStatus: undefined,
        invetNum: 0,
        shareStatus: undefined,
        askStatus: undefined,
        milkStatus: undefined,
        programNum: 0,
        milkDripsNum: 0,
        isDelete: 0,
        updateTime: new Date(),
        signStatus: undefined,
        signNum: 0,
        version: 0,
      }
    }
  },
  async created() {
    // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (this.$route.query.id) {
      const res = await findUserInfo({ ID: this.$route.query.id })
      if (res.code === 0) {
        this.formData = res.data.reuserInfo
        this.type = 'update'
      }
    } else {
      this.type = 'create'
    }
    await this.getDict('状态')
  },
  methods: {
    async save() {
      let res
      switch (this.type) {
        case 'create':
          res = await createUserInfo(this.formData)
          break
        case 'update':
          res = await updateUserInfo(this.formData)
          break
        default:
          res = await createUserInfo(this.formData)
          break
      }
      if (res.code === 0) {
        this.$message({
          type: 'success',
          message: '创建/更改成功'
        })
      }
    },
    back() {
      this.$router.go(-1)
    }
  }
}
</script>

<style>
</style>
